using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;

namespace Granite.Wcf.PocoService
{
	class SimpleInstanceContextProvider : IInstanceContextProvider
	{
		// This provider simply requests that WCF creates a new instance context for each incoming
		// message. More information later on the post about IInstanceContextProvider.
		/// <summary>
		/// Called when a new message is received.
		/// </summary>
		/// <returns>
		/// The <see cref="T:System.ServiceModel.InstanceContext"></see> object that is used to process the message; return null to instruct  to create a new <see cref="T:System.ServiceModel.InstanceContext"></see> object.
		/// </returns>
		/// <param name="message">
		/// The incoming message.
		/// </param>
		/// <param name="channel">
		/// The channel that received the message.
		/// </param>
		public InstanceContext GetExistingInstanceContext(Message message, IContextChannel channel)
		{
			return null;
		}
		/// <summary>
		/// Called when null is returned from the <see cref="M:System.ServiceModel.Dispatcher.IInstanceContextProvider.GetExistingInstanceContext(System.ServiceModel.Channels.Message,System.ServiceModel.IContextChannel)"></see> method.
		/// </summary>
		/// <param name="instanceContext">
		/// The new <see cref="T:System.ServiceModel.InstanceContext"></see> object.
		/// </param>
		/// <param name="message">
		/// The incoming message.
		/// </param>
		/// <param name="channel">
		/// The channel that received the message.
		/// </param>
		public void InitializeInstanceContext(InstanceContext instanceContext, Message message, IContextChannel channel)
		{
		}
		/// <summary>
		/// Called when all <see cref="T:System.ServiceModel.InstanceContext"></see> activities have completed to enable implementers to prevent the <see cref="T:System.ServiceModel.InstanceContext"></see> from being recycled.
		/// </summary>
		/// <returns>
		/// true if  is to close and recycle the <see cref="T:System.ServiceModel.InstanceContext"></see> object and adjust the value of <see cref="P:System.ServiceModel.Dispatcher.ServiceThrottle.MaxConcurrentInstances"></see>; otherwise, false.
		/// </returns>
		/// <param name="instanceContext">
		/// The <see cref="T:System.ServiceModel.InstanceContext"></see> object that is considered idle.
		/// </param>
		public bool IsIdle(InstanceContext instanceContext)
		{
			return true;
		}
		/// <summary>
		/// Called when the <see cref="M:System.ServiceModel.Dispatcher.IInstanceContextProvider.IsIdle(System.ServiceModel.InstanceContext)"></see> method returns false to enable implementers to provide a callback to notify  when the <see cref="T:System.ServiceModel.InstanceContext"></see> object is finished.
		/// </summary>
		/// <param name="callback">
		/// The <see cref="T:System.ServiceModel.Dispatcher.InstanceContextIdleCallback"></see> object that notifies  when the <see cref="T:System.ServiceModel.InstanceContext"></see> object is to be closed and recycled.
		/// </param>
		/// <param name="instanceContext">
		/// The current <see cref="T:System.ServiceModel.InstanceContext"></see>. 
		/// </param>
		public void NotifyIdle(InstanceContextIdleCallback callback, InstanceContext instanceContext)
		{
		}
	}
}
